package 力扣日常刷题.木22二月.第16天222;

import java.util.HashSet;
import java.util.List;

/**
 * @author 帅小伙
 * @date 2022/2/22
 * @description
 * 动态规划
 */
public class Demo133单词拆分 {

    public boolean wordBreak(String s, List<String> wordDict) {
        int len = s.length();
        boolean[] dp = new boolean[len +1];
        dp[0] = true;
        HashSet<String> set = new HashSet<>(wordDict);

        for (int i = 1; i <= len; i++) {
            for (int j = 0; j < i; j++) {
                if(dp[j] && set.contains(s.substring(j,i))) {
                    dp[i] = true;
                    break;
                }
            }
        }
        return dp[len];
    }

}
